<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
    <base href="<%=basePath%>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"> 
 	<%@ include file="/common/importJsCss.jsp" %>
 	<script type="text/javascript" id="preJavascript">
$(function(){
	var jsonObjs = {states:{rect4:{type:'start'},rect5:{type:'end'}},dots:[{x:244,y:232},{x:2,y:3}]};
	//1.读取json
	//方式1
    out("jsonObjs.state.rect4.type",jsonObjs.states.rect4.type);
    //方式2
    out("jsonObjs.state.['rect4'].type",jsonObjs.states['rect4'].type);
    //2.遍历json
    for (var rect in jsonObjs.states){
		out("rect,type",rect+","+jsonObjs.states[rect].type);
	}
	for (var dot in jsonObjs.dots){
		out("dot,x,y",dot+","+jsonObjs.dots[dot].x+","+jsonObjs.dots[dot].y);
	}
	//3.json无该变量
	out("jsonObjs.states.noDefineAttr",jsonObjs.states.noDefineAttr);
	out("jsonObjs.states.noDefineAttr==null",jsonObjs.states.noDefineAttr==null);
	//4.json层次
	var levelJsonObjs = [[],[]];
	out("[[],[]].length",levelJsonObjs.length);
	out("[[],[]]",levelJsonObjs);
});
	</script>
  </head>  
  <body>
	<div class="container">
        <div class="page-header">
            <h2>复杂的json处理</h2>
        </div>
<pre class="prettyprint linenums"></pre>
    </div>
  </body>
</html>
